/*
 PMProfileList.h
 Date Created: February 16, 2010
 
 Author: Karol Krizka <kkrizka@gmail.com>
 
 Copyright (C) 2010 Green-Power
 
 URL: http://code.google.com/p/green-power
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 3 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
 $Id$
 */

#import <Foundation/Foundation.h>

#import "PMProfile.h"

/**
 * Manages all profiles and contains helper functions for adding/deleting new
 * profiles.
 */
@interface PMProfileList : NSObject {
  NSManagedObjectContext *managedObjectContext;
}

@property (nonatomic,retain) NSManagedObjectContext *managedObjectContext;

/**
 * Constructor. The profile list needs to know what data store to read the 
 * profile list from.
 *
 * \param managedObjectContext Read from the data store
 */
- (PMProfileList *)initWithManagedObjectContext:(NSManagedObjectContext *)managedObjectContext;

/**
 * Delete a profile from the list.
 * Fails if:
 * <ul>
 *  <li>Profile does not exist</li>
 *  <li>Profile is the active profile</li>
 * </ul>
 *
 * \param profileName The name of the profile to delete
 *
 * \return YES on success, NO on fail
 */
- (BOOL)deleteProfile:(NSString *)profileName;

/**
 * Create a new profile with default values.
 *
 * Fails if:
 * <ul>
 *  <li>Profile name contains invalid characters</li>
 *  <li>A profile with the profile name already exists</li>
 * </ul>
 *
 * \param profileName The name of the profile to create
 *
 * \return Reference to the new profile on success, nil on failure
 */
- (PMProfile *)createProfile:(NSString *)profileName;

/**
 * \return The active profile
 */
- (PMProfile *)activeProfile;

/**
 * Sets a new profile to be active. This is the recommeded way of activating
 * a profile and not PMProfile setActive, because it makes sure you do not 
 * forget to deactive the currently active profile.
 *
 * \param newActiveProfile The profile to make active
 */
- (void)setActiveProfile:(PMProfile *)newActiveProfile;

/**
 * Find profile for name.
 *
 * \param profileName Profile name to look for
 *
 * \return The profile corresponding to the name, nil if not found.
 */
- (PMProfile *)profileForName:(NSString *)profileName;

/**
 * Saves the profile list to disk. This is done by saving the associated 
 * managed object context.
 *
 * \return YES on success, NO on failure
 */
- (BOOL)save;

/**
 * \return List of all profiles
 */
- (NSArray *)listAllProfiles;

/**
 * Checks if the profile name follows the correct formatting rules. A
 * valid profile name is not blank and contains only alphanumberic 
 * characters.
 *
 * \param profileName Profile name to check.
 *
 * \return YES if the profile name is valid, NO otherwise
 */
- (BOOL)isProfileNameValid:(NSString *)profileName;

/**
 * Checks if the profile name is unique (does not already exist in 
 * the profile list).
 *
 * \param profileName Profile name to check.
 *
 * \return YES if the profile name is unique, NO otherwise
 */
- (BOOL)isProfileNameUnique:(NSString *)profileName;

@end
